home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Graphics 2D / Super Snapshot / Snapshot.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-10-06  |  6.2 KB  |  183 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Snapshot.h
  3.  
  4.     Contains:    This application demonstrates how to quickly and        
  5.                 efficiently capture the main device's desktop into            
  6.                 a window.  The program basically reads the image             
  7.                 stored in the the main device's pixmap then copies            
  8.                 it to a custom pixmap.  The custom pixmap is de-            
  9.                 fined at the same depth of the main device and                 
  10.                 contains an identical copy of that device's color-            
  11.                 table.  This is done to provide the fastest                 
  12.                 performance possible when copying from an offscreen            
  13.                 to onscreen pixmap.  By making sure the pixel values        
  14.                 map to the exact same colors in both colortables,            
  15.                 copybits will do a direct transfer of bits without            
  16.                 wasting time remapping the colors.  Also the ctSeed            
  17.                 field for each colortable should be the same.  Finally,        
  18.                 since the main device's bounding rect is different            
  19.                 than that of the offscreen's, the copying performance        
  20.                 for the device to the offscreen is slightly affected        
  21.                 because of the scaling required.  However, the copying        
  22.                 performance for the offscreen to the window is the             
  23.                 best possible since the bounding rects for each are            
  24.                 identical.
  25.                 
  26.                 (Updated Description)
  27.                 While "carbonizing" this particular sample, I decided 
  28.                 to add a bunch of "bells and whistles" to the sample 
  29.                 which I had seen in other samples.  In addition, I decided 
  30.                 to do a near "full" carbonization of the sample.  I've 
  31.                 added some "conditional" logic so that the menus will 
  32.                 appear correctly for OS 9 and X (no File->Quit menu 
  33.                 under X). I also added support for the "Quit" AppleEvent, 
  34.                 so that under OS X selecting "Application Menu"->Quit would 
  35.                 exit the program.  In addition, dynamic resizing of windows, 
  36.                 setting the size of the windows, saving the screenshot to 
  37.                 a pict file, refreshing the snapshot, as well as multiple 
  38.                 windows were all added to the program.  Lastly, on OS 9, 
  39.                 a menu items will set the desktop picture using Apple 
  40.                 Events. While on OS X, a full screen mode display of a 
  41.                 snapshot will be displayed (since the method to set the 
  42.                 desktop picture on OS X was not available at the time 
  43.                 of this writing).                                    
  44.  
  45.     Written by: JM    
  46.  
  47.     Copyright:    Copyright © 1991-2000 by Apple Computer, Inc., All Rights Reserved.
  48.  
  49.                 You may incorporate this Apple sample source code into your program(s) without
  50.                 restriction. This Apple sample source code has been provided "AS IS" and the
  51.                 responsibility for its operation is yours. You are not permitted to redistribute
  52.                 this Apple sample source code as "Apple sample source code" after having made
  53.                 changes. If you're going to re-distribute the source, we require that you make
  54.                 it clear in the source that the code was descended from Apple sample source
  55.                 code, but that you've made changes.
  56. */
  57.  
  58. #ifndef __SNAPSHOT__
  59. #define __SNAPSHOT__
  60.  
  61. //#includes...
  62.  
  63. #include "CarbonPrefix.h"
  64. #include <Movies.h>
  65. #include <Quicktime.h>
  66. #include <Navigation.h>
  67. #include <Script.h>
  68. #include <Files.h>
  69. #include <AppleEvents.h>
  70. #include <Errors.h>
  71. #include <Events.h>
  72. #include <Fonts.h>
  73. #include <Gestalt.h>
  74. #include <Memory.h>
  75. #include <Menus.h>
  76. #include <OSUtils.h>
  77. #include <QDOffscreen.h>
  78. #include <QuickDraw.h>
  79. #include <Resources.h>
  80. #include <Script.h>
  81. #include <ToolUtils.h>
  82. #include <Windows.h>
  83. #include <TextEdit.h>
  84. #include <Dialogs.h>
  85. #include <Displays.h>
  86. #include <AEPackObject.h>
  87. #include <AEObjects.h>
  88. #include <AERegistry.h>
  89. #include <AEDataModel.h>
  90.  
  91. /* Constant Declarations */
  92.  
  93. #define MENU_BAR_ID            128
  94. #define MENU_BAR_IDX         129
  95.  
  96. #define ABOUT                1
  97. #define ABOUTDLG            128
  98.  
  99. enum {
  100.     ABOUT_MENU = 128,
  101.     FILE_MENU,
  102.     FILE_MENUX,
  103.     SIZE_MENU,
  104.     SPECIAL_MENU,
  105.     SPECIAL_MENUX
  106. };
  107.  
  108. //Note this constant does not include the "Quit" item
  109. #define NUMBER_OF_FILE_MENU_ITEMS 4
  110. enum {
  111.     FILE_NEW = 1,
  112.     FILE_REFRESH,
  113.     FILE_CLOSE,
  114.     FILE_SAVE,
  115.     FILE_QUIT
  116. };
  117.  
  118. #define NUMBER_OF_SIZES 3
  119. enum {
  120.     SIZE_QUARTER_SCALE = 1,
  121.     SIZE_HALF_SCALE,
  122.     SIZE_FULL_SCALE
  123. };
  124.  
  125.  
  126.  
  127. #define NUMBER_OF_SPECIALS 1
  128. enum {
  129.     SPECIAL_CONFUSING = 1
  130. };
  131.  
  132. // Prototypes
  133. void initMac();
  134. void destroyAllWindows();
  135. void setUp();
  136. Boolean onOSX();
  137. void handleMenuSelection(long result);
  138. void handleKeyPress(EventRecord *);
  139. void saveToPICTFile();
  140. WindowPtr createWindow();
  141. void resizeWindow(WindowPtr theWindow);
  142. void doDynamicResizing(WindowPtr theWindow);
  143. void doConfusion();
  144. void disposeWindow(WindowPtr);
  145. void writePictToFile(FSSpec *fspec, PicHandle picHandle);
  146. OSErr SetDesktopPict(AEDesc* pAEDesc,SInt32 pIndex);
  147. static OSErr MakePictureProperty(SInt32 pIndex, AEDesc* containerObjPtr, AEDesc* propertyObjPtr);
  148. void calculateSystemBounds();
  149. PixMapHandle createScreenPixMap();
  150. void drawImage(WindowPtr);
  151. void doNewSnapshot();
  152. void adjustMenus();
  153. pascal OSErr AEQuitHandler(const AppleEvent *messagein, AppleEvent *reply, unsigned long refIn);
  154. void doEventLoop();
  155. void doTrickEventLoop();
  156. void processEvent(EventRecord *anEvent);
  157.  
  158. static OSErr LaunchProcessBySignature(const OSType pTargetType,const OSType pTargetCreator,ProcessSerialNumberPtr psnPtr);
  159. static OSErr Find_DTDB_APPL(const OSType pTargetCreator,FSSpec* pFSSpecPtr);
  160. static OSErr Search_Volumes(const OSType pTargetType,const OSType pTargetCreator,FSSpec* pFSSpecPtr);
  161. static OSErr Search_Volume(const SInt16 pVRefNum,const OSType pTargetType,const OSType pTargetCreator,FSSpec* pFSSpecPtr);
  162.  
  163. pascal    OSErr    AEHMakeEventSignatureTarget( const OSType targetType,
  164.                                                   const OSType targetCreator,
  165.                                                   const AEEventClass eventClass,
  166.                                                   const AEEventID eventID,
  167.                                                         AppleEvent *theEventPtr );
  168. pascal    OSErr    AEHSendEventNoReturnValue( const AEIdleUPP idleProcUPP,
  169.                                            const AppleEvent *theEvent );
  170. pascal OSErr    AEHMakeEventProcessTarget( const ProcessSerialNumberPtr psnPtr,
  171.                                            const AEEventClass eventClass,
  172.                                            const AEEventID eventID,
  173.                                                  AppleEvent *theEventPtr );
  174. pascal    OSErr    AEHGetHandlerError( const AppleEvent *reply );
  175. pascal    OSErr    FindProcessBySignature( const OSType targetType,
  176.                                         const OSType targetCreator,
  177.                                               ProcessSerialNumberPtr psnPtr );
  178. pascal    OSErr    OHMakeAliasDescFromFSSpec( const FSSpecPtr fssPtr,
  179.                                                   AEDesc *aliasDescPtr );
  180. pascal    OSErr    OHMakeAliasDesc( const AliasHandle aliasHandle,
  181.                                         AEDesc *aliasDescPtr );
  182.                                         
  183. #endif